/*
 * @Author: Zhang Kai
 * @Date: 2021-10-29 15:07:32
 * @LastEditors: mayijun
 * @LastEditTime: 2022-08-09 17:52:50
 * @FilePath: /metricsx-standard-ui/src/store/index.ts
 */
import { InjectionKey } from 'vue';
import { createStore, Store, useStore as baseUseStore } from 'vuex';
import breadcrumb from './modules/breadcrumb';
import indexlibrary from './modules/indexlibrary';
import metrics from './modules/metrics';
import dimension from './modules/dimension';
import system from './modules/system';
import model from './modules/model';
import modifier from './modules/modifier';
import statistics from './modules/statistics';
import datamanage from './modules/datamanage';
import VuexPersistence from 'vuex-persist';
import metricsdevelop from './modules/metricsdevelop';
import indextree from './modules/indextree';
import scenesManage from './modules/scenesManage';
import metricsapplication from './modules/metricsapplication';

// define your typings for the store state
export interface State {
  [key: string]: any;
  breadcrumb?: any; // modules中使用
  count: number;
  systemInfo: { width: number; height: number };
}

// define injection key
export const key: InjectionKey<Store<State>> = Symbol();

const vuexLocal = new VuexPersistence<any>({
  key: 'Vuex-Persistence',
  storage: window.sessionStorage,
  modules: ['datamanage', 'indextree']
});
export const store = createStore<State>({
  state: {
    count: 0,
    systemInfo: { width: 1920, height: 1080 }
  },
  actions: {},
  modules: {
    breadcrumb,
    indexlibrary,
    metrics,
    dimension,
    system,
    model,
    statistics,
    datamanage,
    modifier,
    metricsdevelop,
    indextree,
    scenesManage,
    metricsapplication
  },
  plugins: [vuexLocal.plugin]
});

export function useStore() {
  return baseUseStore(key);
}
